package user.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 检查图片验证码
 */
@WebServlet("/CheckPicCodeServlet")
public class CheckPicCodeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取用户输入的验证码
        String userCode=request.getParameter("code");
        //从session中取出验证码
        String code=(String) request.getSession().getAttribute("picCode");

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        if(code!=null && code.equalsIgnoreCase(userCode)){
            out.print(true);
        }else{
            out.print(false);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
